<template>
	<view>
		<!-- 顶部导航栏 -->
		<view class="hander-tab">
			<view class="hander-text">
				我的
			</view>
		</view>
		<!-- 用户资料 -->
		<view class="" style="margin: 30rpx;display: flex;">
			<image @click="tologin" :src="userinfo.user_pic"
				style="width: 250rpx;height: 250rpx;border-radius: 10rpx 50rpx 50rpx 50rpx;margin-right: 50rpx;background-image: linear-gradient(to top, #feada6 0%, #f5efef 100%);"
				mode=""></image>
			<view class="" style="width: 400rpx;">
				<view style="height: 130rpx;display: flex;flex-direction: column;">
					<view @click="tologin" class="" style="font-size: 50rpx;">{{userinfo.nickname?userinfo.nickname:'请登录'}}</view>
					<view v-if="userinfo&&userinfo.rz_type==1" class="" style="display: flex;align-items: center;margin-top: 20rpx;">
						<image src="../../static/rz.png" style="width: 40rpx;height: 40rpx;margin-right: 5rpx;" mode="">
						</image>
						<text style="color: #007eff;">{{userinfo.rz_describe}}</text>
					</view>
				</view>
				<view v-if="userinfo" class="" style="display: flex;justify-content: space-between;margin-top: 20rpx;">
					<view class="" style="display: flex;flex-direction: column;align-items: center;">
						<text style="font-size: 35rpx;font-weight: 700;">{{userinfo.follow_count}}</text>
						<text style="font-size: 35rpx;font-weight: 700;">关注</text>
					</view>
					<view class="" style="display: flex;flex-direction: column;align-items: center;">
						<text style="font-size: 35rpx;font-weight: 700;">{{userinfo.fans_count}}</text>
						<text style="font-size: 35rpx;font-weight: 700;">粉丝</text>
					</view>
					<view class="" style="display: flex;flex-direction: column;align-items: center;">
						<text style="font-size: 35rpx;font-weight: 700;">{{userinfo.like_count}}</text>
						<text style="font-size: 35rpx;font-weight: 700;">获赞</text>
					</view>
				</view>
			</view>
		</view>
		<view class="common-title">广告</view>
		<!-- AD -->
		<view v-if="imagesList.length" class="" style="margin: 30rpx;">
			<u-swiper bgColor="#ffffff" :list="imagesList" key-name="banner_img_url" :radius="5" height="130" @change="changeswiper"
				:current="swiperindex" :autoplay="false">
				<view slot="indicator" class="indicator">
					<view class="indicator__dot" v-for="(item, index) in imagesList" :key="index"
						:class="[index === swiperindex && 'indicator__dot--active']">
					</view>
				</view>
			</u-swiper>
		</view>
		<!-- 设置 -->
		<view class="" style="margin: 30rpx;">
			<view @click="tomore(item)" v-for="(item,index) in list" v-if="userinfo||index==2" class="" style="display: flex;align-items: center;margin: 50rpx 0;">
				<u-icon :name="item.icon" color="#333333" size="28"></u-icon>
				<text style="margin-left: 50rpx;">{{item.title}}</text>
			</view>
			<u-button v-if="userinfo" @click="exit" type="error" text="退出登录"></u-button>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	const dbCmd = db.command
	export default {
		data() {
			return {
				list:[{
					title:"身份认证",
					icon:"checkmark-circle",
					path:"/pages/about/about"
				},{
					title:"关于小镇",
					icon:"list",
					path:"/pages/about/about"
				}],
				userinfo:null,
				swiperindex: 0,
				imagesList: [],
				src: 'https://mp-31440ed7-4eb2-4aba-87ef-f56b378cc54c.cdn.bspapp.com/cloudstorage/be442af0-cb27-4b99-9d30-72b5317fc2ff.jpg',
			}
		},
		onShow() {
			this.getuserinfo()
		},
		onLoad() {
			this.getbanner()
		},
		methods: {
			tomore(i){
				uni.navigateTo({
					url:i.path
				})
			},
			exit(){
				uni.removeStorageSync('userinfo')
				uni.showToast({
					title:"退出成功",
					success() {
						setTimeout(res=>{
							uni.reLaunch({
								url:'/pages/mine/mine'
							})
						},300)
					}
				})
			},
			//获取轮播
			getbanner(){
				uni.request({
					url:'https://xzapi.knowwl.cn/api/getbanner',
					data:{
						type:1
					},
					success: (res) => {
						console.log(res);
						this.imagesList=res.data.results
					}
				})
			},
			//取出本地存储的用户信息
			getuserinfo(){
				uni.getStorage({
					key:'userinfo',
					success: (res) => {
						console.log(res);
						this.$http({
							url:'/api/commonuserinfo',
							data:{
								user_id:res.data.id
							}
						}).then(res=>{
							this.userinfo=res.data
							console.log(res);
						})
					}
				})
			},
			//跳转登录页
			tologin(){
				if (this.userinfo) {
					uni.navigateTo({
						url:'/pages/userinfo/userinfo?user_id='+this.userinfo.user_id
					})
				} else{
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			},
			changeswiper(e) {
				this.swiperindex = e.current
			},
		}
	}
</script>

<style lang="scss">
	.hander-tab {
		position: sticky;
		z-index: 99;
		top: 0;
		display: flex;
		justify-content: space-between;
		/* #ifdef MP-WEIXIN */
		padding: 80rpx 20rpx 0rpx 20rpx;
		/* #endif */
		/* #ifndef MP-WEIXIN */
		padding: 0 20rpx;
		/* #endif */
		height: 100rpx;
		align-items: center;
		background-color: #ffffff;
	}

	.hander-text {
		font-size: 40rpx;
	}
	
	.common-title {
		margin: 30rpx;
		padding: 0 20rpx;
		display: flex;
		align-items: center;
		border-left: 10rpx solid #3668fc;
	}
	
	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}
</style>